package com.aaa.project.service.impl;


import com.aaa.entity.UCollection;
import com.aaa.entity.UUserInfo;
import com.aaa.project.mapper.UCollectionMapper;
import com.aaa.project.mapper.UUserInfoMapper;
import com.aaa.project.service.IUCollectionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.security.Principal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhangxuhui
 * @since 2023-02-02
 */
@Service
public class UCollectionServiceImpl extends ServiceImpl<UCollectionMapper, UCollection> implements IUCollectionService {

    @Resource
    private UCollectionMapper uCollectionMapper;

    @Resource
    private UUserInfoMapper uUserInfoMapper;


    /**
     * 商品收藏
     * @param principal
     * @return
     */
    @Override
    public  List<Map<String,Object>> getUserSoucang(Principal principal) {
        String name = principal.getName();
        // 根据当前的人的名字用户的id
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("telephone",name);
        UUserInfo one = uUserInfoMapper.selectOne(queryWrapper);
        List<Map<String,Object>> list=uCollectionMapper.find(one.getId());
        return list;
    }

    /**
     * 店铺关注
     * @param principal
     * @return
     */
    @Override
    public List<Map<String, Object>> findDian1(Principal principal) {
        String name = principal.getName();
        // 根据当前的人的名字用户的id
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("telephone",name);
        UUserInfo one = uUserInfoMapper.selectOne(queryWrapper);
        List<Map<String,Object>> list=uCollectionMapper.findDian(one.getId());
        return list;
    }
}
